<template>
  <div class="meeting-info">
    <div class="info-item">
      <div class="label">会议主题</div>
      <div class="value title">{{ meetingInfo?.activity?.title || '-' }}</div>
    </div>

    <div class="info-item">
      <div class="label">座位图</div>
      <div class="value seat-map">
        <el-button :disabled="!meetingInfo?.activity?.seatedImg" link type="primary" @click="showSeatMap">
          {{ meetingInfo?.activity?.seatedImg ? '查看座位图' : '暂无座位图' }}
        </el-button>
      </div>
    </div>
  </div>

  <!-- 座位图弹窗 -->
  <el-dialog v-model="dialogVisible" :close-on-click-modal="true" :modal="true" :show-close="true" title="会议座位图" width="80%">
    <div class="seat-map-container">
      <el-image class="seat-map-image" fit="contain" :src="meetingInfo?.activity?.seatedImg">
        <template #error>
          <div class="image-error">
            <el-icon><picture-filled /></el-icon>
            <span>图片加载失败</span>
          </div>
        </template>
      </el-image>
    </div>
  </el-dialog>
</template>

<script lang="ts" setup>
import { PictureFilled } from '@element-plus/icons-vue'
import { computed, ref } from 'vue'

defineOptions({
  name: 'DataScreenRight1',
})

interface Player {
  id: string
  name: string
  mobile: string
  attendMeetingStatus: number
  isCheck: boolean
  checkType: string | null
  checkTime: string | null
}

interface MeetingInfo {
  activity: {
    id: string
    title: string
    status: string | null
    startTime: string
    endTime: string
    conferenceRoomId: string
    subscribers: string
    compere: string | null
    seatedImg: string
    remark: string
    createdAt: string
    updatedAt: string
  }
  players: {
    count: number
    rows: Player[]
  }
}

const props = defineProps<{
  meetingInfo?: MeetingInfo
}>()

// 弹窗控制
const dialogVisible = ref(false)

// 显示座位图
const showSeatMap = () => {
  if (props.meetingInfo?.activity?.seatedImg) {
    dialogVisible.value = true
  }
}

// 格式化参会人员显示
const formatAttendees = computed(() => {
  if (!props.meetingInfo?.players?.rows) return '-'

  const players = props.meetingInfo.players.rows
  const maxDisplay = 3 // 最多显示3个人
  const totalCount = players.length

  if (totalCount <= maxDisplay) {
    return players.map((p) => p.name).join('、')
  } else {
    const displayNames = players
      .slice(0, maxDisplay)
      .map((p) => p.name)
      .join('、')
    const remainingCount = totalCount - maxDisplay
    return `${displayNames} 等 ${remainingCount} 人`
  }
})
</script>

<style lang="scss" scoped>
.meeting-info {
  height: 100%;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 20px;

  .info-item {
    position: relative;
    padding-left: 12px;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 4px;
      width: 3px;
      height: calc(100% - 8px);
      background: linear-gradient(to bottom, #7367f0, transparent);
      border-radius: 3px;
    }

    .label {
      font-size: 14px;
      color: rgba(255, 255, 255, 0.6);
      margin-bottom: 8px;
      display: flex;
      align-items: center;
      gap: 8px;

      &::after {
        content: '';
        flex: 1;
        height: 1px;
        background: linear-gradient(90deg, rgba(115, 103, 240, 0.3), transparent);
      }
    }

    .value {
      color: rgba(255, 255, 255, 0.9);
      font-size: 15px;
      line-height: 1.6;
      transition: all 0.3s ease;

      &.title {
        font-size: 18px;
        font-weight: 500;
        color: #7367f0;
        text-shadow: 0 0 10px rgba(115, 103, 240, 0.3);
        letter-spacing: 1px;
      }

      &.time {
        div {
          margin-bottom: 8px;
          display: flex;
          align-items: center;
          gap: 8px;

          &::before {
            content: '';
            width: 6px;
            height: 6px;
            background: #7367f0;
            border-radius: 50%;
            box-shadow: 0 0 10px rgba(115, 103, 240, 0.5);
          }
        }
      }

      &.attendees {
        font-size: 14px;
      }

      &.remark {
        font-size: 14px;
        color: rgba(255, 255, 255, 0.7);
        max-height: 80px;
        overflow-y: auto;
        white-space: pre-wrap;
        word-break: break-all;
        padding-right: 10px;

        /* 自定义滚动条样式 */
        &::-webkit-scrollbar {
          width: 4px;
        }

        &::-webkit-scrollbar-thumb {
          background-color: rgba(115, 103, 240, 0.3);
          border-radius: 2px;
        }

        &::-webkit-scrollbar-track {
          background-color: rgba(255, 255, 255, 0.05);
        }
      }

      &.seat-map {
        .el-button {
          padding: 0;
          height: auto;
          font-size: 14px;
          color: #7367f0 !important;

          &:hover {
            color: lighten(#7367f0, 10%) !important;
            text-shadow: 0 0 10px rgba(115, 103, 240, 0.5);
          }

          &:disabled {
            color: rgba(255, 255, 255, 0.4) !important;
          }
        }
      }
    }
  }
}

.seat-map-container {
  width: 100%;
  height: 70vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(115, 103, 240, 0.1);
  border-radius: 10px;
  border: 1px solid rgba(115, 103, 240, 0.2);

  .seat-map-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .image-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;

    .el-icon {
      font-size: 32px;
      margin-bottom: 8px;
      color: rgba(255, 255, 255, 0.4);
    }
  }
}

:deep(.el-dialog) {
  background: #1b1e3c;
  border: 1px solid rgba(115, 103, 240, 0.3);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);

  .el-dialog__header {
    margin: 0;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(115, 103, 240, 0.2);

    .el-dialog__title {
      color: rgba(255, 255, 255, 0.9);
      font-size: 16px;
      font-weight: 500;
    }

    .el-dialog__close {
      color: rgba(255, 255, 255, 0.6);
      &:hover {
        color: #7367f0;
      }
    }
  }

  .el-dialog__body {
    padding: 20px;
    color: rgba(255, 255, 255, 0.9);
  }
}
</style>
